<?PHP
    $pp_path="..";
    include_once ($pp_path."/common.php");

    if (empty($page))
        $page=1;

    if ($key)
        $searchQuery=" WHERE $key LIKE '%$keyword%'";

    $query="SELECT r_idx FROM gcm_result$searchQuery";
    $count=boardCount($query, $page);
    $query="SELECT r_idx, p_code, r_sender, r_subject, r_status, r_regdate FROM gcm_result$searchQuery ORDER BY r_regdate DESC LIMIT {$count['start_record']}, {$pp['page_per_record']}";
    $result=$mysql->query($query);
?>
<!DOCTYPE HTML>
<html>
<head>
    <link href="/css/jquery-ui-1.10.2.custom.min.css" rel="stylesheet" />
    <link href="/css/base.css" rel="stylesheet" />
</head>
<body>
    <div id="result">
        <table>
        <tr>
            <th style="width: 80px;">No</th>
            <th>Subject</th>
            <th style="width: 120px;">Sender</th>
            <th style="width: 60px;">Result</th>
            <th style="width: 120px;">Date</th>
            <th style="width: 60px;">Edit</th>
            <th style="width: 60px;">Delete</th>
        </tr>
        <?PHP
            while($row=$mysql->fetch_array($result)) {
                if ($key)
                    $row[$key]=str_replace("$keyword", "<font style=\"font-weight: bold; color: #CC0000\">$keyword</font>", $row[$key]);
        ?>
        <tr>
            <td><?PHP echo $count['no']--; ?></td>
            <td><?PHP echo $row['r_subject']?></td>
            <td><?PHP echo $row['r_sender']?></td>
            <td><?PHP if ($row['r_status']==2) { echo "READY"; } elseif ($row['r_status']==1) { echo "SUCCESS"; } else { echo "FAILED"; } ?></td>
            <td><?PHP echo date("Y-m-d H:i", $row['r_regdate']); ?></td>
            <td><?PHP if ($row['r_status']!=1) { ?><img src="/images/btn_edit.gif" /><?PHP } ?></td>
            <td><img src="/images/btn_delete.png" /></td>
        </tr>
        <?PHP } ?>
        <?PHP if ($count['total_record']<1) { ?>
        <tr>
            <td colspan="7">No Result List</td>
        </tr>
        <?PHP } ?>
        </table>
        <?PHP echo getPaging($pp['block_per_page'], $count['now_page'], $count['total_page'], $_SERVER['PHP_SELF'], "&key=$key&keyword=$keyword"); ?>
        <div id="search">
            <form id="searchFrm" name="searchFrm" method="get" action="<?PHP echo $_SERVER['PHP_SELF']; ?>">
            <input type="hidden" id="p_code" name="p_code" value="<?PHP echo $p_code; ?>" />
            <select id="key" name="key">
                <option value="d_code"<?PHP if ($key=="d_code") { echo " selected=\"selected\""; } ?>>Device Code</option>
            </select>
            <input type="text" id="keyword" name="keyword" value="<?=$keyword?>" />
            <a id="btn_search" class="btn">SEARCH</a>
            </form>
        </div>
    </div>
    <script src="/script/jquery-1.9.1.js"></script>
    <script src="/script/jquery-ui-1.10.2.custom.min.js"></script>
    <script>
    $(function(){
        $(".btn").button();
        $("#btn_search").click(function(){
            if (!$.trim($("#keyword").val())) {
                alert("Please Insert Keyword");
                $("#keyword").focus();
                return false;
            }
            $("#searchFrm").submit();
        });

        $("#searchFrm").keypress(function(e){
            if (e.keyCode==13) {
                if (!$.trim($("#keyword").val())) {
                    alert("Please Insert Keyword");
                    $("#keyword").focus();
                    return false;
                }
                $("#searchFrm").submit();
            }
        });
    });
    </script>
</body>
</html>